/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-07 16:52:12
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-02-01 15:00:43
 * @FilePath: \My-bolg\My_Blog\src\stores\baseSiteInfo.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, computed, nextTick } from 'vue'
import { defineStore } from 'pinia'
export const SiteInfoStore = defineStore('siteinfo', {
    // 数据存到store里刷新页面会重置，持久化就不会了
    persist: {
        enabled: true, //开启数据持久化
        strategies: [
            {
                key: "siteinfo", //给一个要保存的名称
                storage: localStorage, //sessionStorage / localStorage 存储方式
            },
        ],
    },
    state: () => ({
        latitude: "", //纬度,
        longitude: "",/* 经度 */
        // md预览主题列表
        previewThemeList: ["default", "github", "vuepress", "mk-cute", "smart-blue", "cyanosis"],
        // md代码主题列表
        codeThemeList: [
            "atom",
            "a11y",
            "github",
            "gradient",
            "kimbie",
            "paraiso",
            "qtcreator",
            "stackoverflow",
        ],
        // md预览主题
        previewTheme: "default",
        // md代码主题
        codeTheme: "atom",
        // 当前主题
        currenttheme: "default",
        themelist: [
            {
                value: "default",
                name: "梦幻蓝"
            }, {
                value: "Pinktheme",
                name: "少女粉"
            },
        ]
    }),
    getters: {
        getinfo() {
            return [parseFloat(this.longitude), parseFloat(this.latitude)]
        },
        getThemelist() {
            return this.themelist
        }
        
    },
    actions: {
        setLatandLong(latitude, longitude) {
            this.latitude = latitude;
            this.longitude = longitude;
        },
        changecodeTheme(theme) {
            if (this.codeThemeList.findIndex(item => item == theme)) {
                this.codeTheme = theme;
            }
        },
        changeprewTheme(theme) {
            if (this.previewThemeList.findIndex(item => item == theme)) {
                this.previewTheme = theme;
            }
        },
        getcurrenttheme() {
            return this.currenttheme;
        },

        changecurrenttheme(theme) {
            this.themelist.map(item => {
                if (item.value == theme) {
                    this.currenttheme = theme;
                    localStorage.setItem("currenttheme", theme);
                    document.documentElement.setAttribute("data-theme",theme);
                }
            })
           
        }

    }
})